<?php


namespace app\common\service\face;



use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;

class ClientTest
{

    public function verify()
    {
        AlibabaCloud::accessKeyClient(env('face.AccessKey_ID'), env('face.AccessKey_Secret'))
            ->regionId('cn-shanghai')
            ->asDefaultClient();
        try {
            $result = AlibabaCloud::rpc()
                ->product('facebody')
                // ->scheme('https') // https | http
                ->version('2019-12-30')
                ->action('CompareFace')
                ->method('POST')
                ->host('facebody.cn-shanghai.aliyuncs.com')
                ->options([
                    'query' => [
                        'RegionId' => "cn-shanghai",
                        // 质量分阈值,小于该阈值则失败
                        'QualityScoreThreshold' => 80,
                        'ImageURLA' => "https://viapi-test.oss-cn-shanghai.aliyuncs.com/demo-center/facebody/DetectFace.jpg",
                        'ImageURLB' => "https://viapi-test.oss-cn-shanghai.aliyuncs.com/demo-center/facebody/DetectFace.jpg",
                    ],
                ])
                ->request();
            dump($result->getStatusCode());
            dump($result->toArray());
        } catch (ClientException $exception) {
            echo $exception->getMessage() . PHP_EOL;
        } catch (ServerException $exception) {
            echo $exception->getMessage() . PHP_EOL;
            echo $exception->getErrorCode() . PHP_EOL;
            echo $exception->getRequestId() . PHP_EOL;
            echo $exception->getErrorMessage() . PHP_EOL;
        }
    }
}